package singleton;

public class Demo {
    private static Demo ins = new Demo();
    private static class DemoHoder {
        static {
            System.out.println("1：内部类被初始化了");
        }
        private static Demo instance = new Demo();
    }
    private Demo() {
        System.out.println("2：本类初始化了");
    }
    Demo(String str) {
        System.out.println("3：有参数的构造初始化了");
    }
    public static Demo getInstance() {
        return DemoHoder.instance;
    }

}
class Client2{
    public static void main(String[] args) throws ClassNotFoundException {
//        Class<?> aClass = Class.forName("singleton.Demo"); // 只会打印2. 是因为静态属性在类加载的时候被初始化赋值
        Demo.getInstance();// 打印 2. 1. 2. 因为 静态属性会先被初始化
    }
}